package com.compty.paint.freemarker;

import java.io.IOException;
import java.util.List;

import com.compty.core.framework.context.spring.SpringContextHolder;
import com.compty.core.page.Page;
import com.compty.paint.domain.Advertisement;
import com.compty.paint.domain.Painter;
import com.compty.paint.domain.Painting;
import com.compty.paint.manager.AdvertisementManager;
import com.compty.paint.manager.PainterManager;
import com.compty.paint.manager.PaintingManager;

import freemarker.template.TemplateException;

/**
 * @Todo:主页生成
 * @author: 朱庆辉
 * @CreateTime:2012-3-23 下午01:47:02
 */
public class IndexGenerate extends BaseGenerate{
	
	
	private PaintingManager paintingManager;
    private PainterManager painterManager;
    private AdvertisementManager advertisementManager;

	public IndexGenerate() {
		paintingManager = SpringContextHolder.getBean("paintingManager");
		painterManager =  SpringContextHolder.getBean("painterManager");
		advertisementManager = SpringContextHolder.getBean("advertisementManager");
	}

	@SuppressWarnings("unchecked")
	public void generateHtml() throws TemplateException, IOException {
		
		Page page  = paintingManager.findPaintingsByPageOfPainterStarByRandom(null, 1, 12);//名家作品 
        List<Painting> paintingListOfPainterStar = (List<Painting>) page.getResult();
        root.put("paintingListOfPainterStar", paintingListOfPainterStar);
        
        page = advertisementManager.findByPage(1,3,"1");
        List<Advertisement> advertisementList = (List<Advertisement>) page.getResult();
        root.put("advertisementList", advertisementList);
        
       /********************************** 画家列表  begin ****************************************/
       List<Painter> painterList = painterManager.getAll();
       root.put("painterList", painterList);
      /********************************** 画家列表   end ****************************************/
       
       output("index.ftl", "", "index.html");
		
	}
}
